package ar.com.digitalbricks.view.imprenta.contacto.action;

import java.util.Collection;

import ar.com.digitalbricks.view.imprenta.cliente.action.ClienteAction;
import ar.com.digitalbricks.view.imprenta.helper.ContactoView;

import com.opensymphony.xwork2.Action;

public class CrearContacto extends ClienteAction {
	private ContactoView contactoView;
	
	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		this.getClienteView().setContactos((Collection<ContactoView>) session.get("contactos"));
		this.getClienteView().addContacto(this.getContactoView());
		session.put("contactos", this.getClienteView().getContactos());
		this.setShowContactoDiv(false);
		return Action.SUCCESS;
	}

	public String preparar() throws Exception {
		this.setContactoView(new ContactoView());
		this.setShowContactoDiv(true);
		return Action.SUCCESS;
	}
	
	public String cancelar() throws Exception {
		this.setContactoView(null);
		this.setShowContactoDiv(false);
		return Action.NONE;
	}
	
	public ContactoView getContactoView() {
		if (this.contactoView == null){
			this.contactoView = new ContactoView();
		}
		return this.contactoView;
	}

	public void setContactoView(ContactoView contactoView) {
		this.contactoView = contactoView;
	}
}